#!/bin/bash
set -e

cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1
export readonly ARCH=${1:-amd64}
export readonly NAME=${2:-$(basename "${PWD%/*}")}
export readonly VERSION=${3:-$(basename "$PWD")}

rm -rf charts

repo_url="https://juicedata.github.io/charts/"
repo_name="juicefs"
chart_name="juicefs/juicefs-csi-driver"

helm repo add ${repo_name} ${repo_url}
helm pull ${chart_name} --version=${VERSION#v} -d charts --untar
yq e -i '.sidecars.livenessProbeImage.repository="dyrnq/livenessprobe"' ./charts/juicefs-csi-driver/values.yaml
yq e -i '.sidecars.livenessProbeImage.tag="v2.1.0"' ./charts/juicefs-csi-driver/values.yaml

yq e -i '.sidecars.csiResizerImage.repository="dyrnq/csi-resizer"' ./charts/juicefs-csi-driver/values.yaml
yq e -i '.sidecars.nodeDriverRegistrarImage.repository="dyrnq/csi-node-driver-registrar"' ./charts/juicefs-csi-driver/values.yaml
yq e -i '.sidecars.csiProvisionerImage.repository="dyrnq/csi-provisioner"' ./charts/juicefs-csi-driver/values.yaml
yq e -i '.sidecars.csiProvisionerImage.tag="v2.1.0"' ./charts/juicefs-csi-driver/values.yaml
